//
//  BTRegisterViewController.m
//  WeChat
//
//  Created by 互联网 on 16/11/1.
//  Copyright © 2016年 bigtree. All rights reserved.
//

#import "BTRegisterViewController.h"

@interface BTRegisterViewController ()
- (IBAction)cancelBtnClick:(id)sender;
- (IBAction)registerBtnClick:(id)sender;
@property (weak, nonatomic) IBOutlet UITextField *registerUsr;
@property (weak, nonatomic) IBOutlet UITextField *registerPsw;

@end

@implementation BTRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)cancelBtnClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)registerBtnClick:(id)sender {
    
    [BTAccout shareAccount].registerUser = self.registerUsr.text;
    [BTAccout shareAccount].registerPsw = self.registerPsw.text;
    
    [BTXMPPTool sharedBTXMPPTool].registerOperation = YES;
    [MBProgressHUD showMessage:@"正在注册..."];
    __weak typeof(self) selfVC = self;
    [[BTXMPPTool sharedBTXMPPTool] xmppRegister:^(XMPPResultType result) {
        [selfVC handleXMPPResultType:result];
    }];
}

-(void)handleXMPPResultType:(XMPPResultType)resultType
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUD];
        if (resultType == XMPPResultTypeRegisterSuccess) {
            [MBProgressHUD showSuccess:@"注册成功"];
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            [MBProgressHUD showSuccess:@"用户用已存在"];
        }
    });
}
-(void)dealloc
{
    NSLog(@"%s",__func__);
}
@end
